home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / sample / docex / docex.tg next >
Text File  |  2002-12-18  |  5KB  |  179 lines

  1. #
  2. #  Examples from user manual
  3. #
  4. #############################################
  5.  
  6. @  $name = "Alaska"      
  7.     $name is the best ! 
  8.  
  9. @  $name = "Alaska"  
  10.     (zmienna \$name)  
  11.    
  12. @  $s = "BAR"                   
  13. @  $n = 2                       
  14. @  $tab[1] = "foo"              
  15. @  $tab[2] = "bar"              
  16. @  $str = [ name: "FOO", count: 4 ]
  17.       $s   $tab[ 1 ]    $tab[ $n ] 
  18.       $str.name, $str.count        
  19.    
  20. @  $tab = ["a","b","c",1000]                  
  21. @  $str = [ name: "FOO", count: 4, val: 1.20 ]
  22. @for ($i=0; $i<$size($tab); $i++)             
  23.      item $i: $tab[ $i ]                      
  24. @endfor                                       
  25.      STRUCTURE:                               
  26. @for ($i in $str)                             
  27.      $i: $str.$i                              
  28. @endfor                                       
  29.                                               
  30. @ $data = [ "scalar", [a:"Alaska", b:"Bar"], \  
  31. @           [1,2,3,4],                       \  
  32. @           10 ]                                
  33.  
  34. @function fun()           
  35.         inline text              
  36. @   return "RESULT TEXT"     
  37. @endfunction                 
  38.    called from data line: $fun()
  39. @ $fun()                     
  40.  
  41. @for ( $i=0; $i<10; $i++ )  
  42.    iteration  $i            
  43. @  break                    
  44. @endfor                     
  45.                             
  46. @switch ( 1 )               
  47. @  case 1:                  
  48.    branch 1                 
  49. @  break                    
  50. @  case 2:                  
  51.    branch 2                 
  52. @endswitch                  
  53.  
  54. @push
  55.  
  56. @embed "header"   
  57. @embed "body"     
  58. @embed "footer"   
  59. @emit  "body"     
  60.   BODY TEXT       
  61. @emit  "footer"   
  62.   FOOTER TEXT     
  63. @emit  "header"   
  64.   HEADER TEXT     
  65.                   
  66. @pop
  67.   
  68. @for ( $i=0; $i<3; $i++ )         
  69.    item  $i                       
  70. @endfor                           
  71.                                   
  72. @  $str = [ a: "FOO", b: "BAR" ]  
  73. @for ( $fld in $str )             
  74.    $fld: $str.$fld                
  75. @endfor                           
  76.    
  77. @function factor( n )               
  78. @  if ( $n == 1 )                   
  79. @     return 1                      
  80. @  else                             
  81. @     return $n * $factor( $n - 1 ) 
  82. @  endif                            
  83. @endfunction                        
  84.                                     
  85. @for ( $i=1; $i<8; $i++ )           
  86.    $i ! = $factor($i)               
  87. @endfor                             
  88.  
  89. @function abc(a,b)  
  90. @local c            
  91.    $a $b $c         
  92. @   $a='anew'       
  93. @   $b='bnew'       
  94. @   $c='cnew'       
  95.    $a $b $c         
  96. @endfunction        
  97.                     
  98. @ $a='a'            
  99. @ $b='b'            
  100. @ $c='c'            
  101.                     
  102. $a $b $c            
  103. @ $abc( $a, $b )    
  104. $a $b $c            
  105.  
  106. @push
  107.  
  108. @output "foo"   
  109.   FOO           
  110. @output "stdout"
  111.   STDOUT        
  112.  
  113. @pop  
  114.  
  115. @push
  116.  
  117. @function decl( d )       
  118. @  push                   
  119. @  output "example.h"     
  120.      $d                   
  121. @  pop                    
  122. @endfunction              
  123.                           
  124. @output "example.c"       
  125.                           
  126. #include "example.h"      
  127.                           
  128. @ $decl( "int i;" )       
  129.                           
  130. int main()                
  131. {                         
  132. @ $decl( "int result;" )  
  133.       return result;      
  134. }                         
  135.  
  136. @pop
  137.  
  138. @function string( len )               
  139. @  if ( $len == 1 )                   
  140. @     return "z"                      
  141. @  else                               
  142. @     return "z" + $string( $len-1 )  
  143. @  endif                              
  144. @endfunction                          
  145.                                       
  146. @switch "zz"                          
  147. @  case $string(1) :                  
  148.       1                               
  149. @     break                           
  150. @  case $string(2) :                  
  151.       2                               
  152. @     break                           
  153. @  case $string(3) :                  
  154.       3                               
  155. @     break                           
  156. @endswitch                            
  157.  
  158.    $printf( "%-10s %d 0x%02X", "foo", 10, 10 ) 
  159.    
  160. @ $x = 1                                        
  161. @ $y = [ 1, 2, 3 ]                              
  162. @ $z = [ a:"foo", b:10 ]                        
  163.                                                 
  164. $size($x)  $size($y)  $size($z)  $size($undef)  
  165.  
  166. @ $x = 1                                 
  167. @ $y = "Foo Bar"                         
  168.                                          
  169. $strlen($x)  $strlen($y)  $strlen($undef)
  170.  
  171. $substr( "ABCDEFGHIJK", 2, 5 ) 
  172. $substr( "ABCDEFGHIJK", 2 )    
  173. $substr( "ABCDEFGHIJK", 2, 50 )
  174.  
  175. $system("ps")   
  176.  
  177. \#line  $tplline()  \"$tplfile()\"    
  178.  
  179.